/**
 * 使用typeof判断对象类型
 * @param {Object} obj 要判断的对象
 * @returns {String}
 */
const byTypeof = function (obj) {
    return typeof obj
}
/**
 * 使用 instanceof 判断对象类型
 * @param {Object} obj 要判断的对象
 * @returns {String}
 */
const byInstanceof = function (obj) {
    const typeArr = [Date, RegExp, Array, Map, Set, Number, Boolean, String, Object]
    for (let i = 0; i < typeArr.length; i++) {
        const item = typeArr[i];
        if (obj instanceof item) return item.name
    }
    return 'unkown object'
}
/**
 * 使用 Object 类型判断对象类型
 * @param {Object} obj 要判断的对象
 * @returns {String}
 */
const byConstructor = function (obj) {
    return Object.prototype.toString.call(obj).slice(8, -1)
}
let mapObj = new Map()
mapObj.set('a', 1)
mapObj.set('b', 2)
let setObj = new Set()
setObj.add('c', 2)
setObj.add('d', 'string')
const objArr = [1, true, 'string', new Date(), /$[123]+/, { a: 1 }, [1, 2, 3], mapObj, setObj, null, undefined]
const funcArr = [byTypeof, byInstanceof, byConstructor]
for (let index = 0; index < funcArr.length; index++) {
    const item = funcArr[index];
    console.log(`--------------${item.name} start --------------`);
    for (let i = 0; i < objArr.length; i++) {
        const objItem = objArr[i];
        const type = item(objItem)
        console.log(objItem, '      ', type, type.toUpperCase());
    }
    console.log(`--------------${item.name} end --------------`);
    console.log(' ');
}
